package com.keeson.android_cli;

import android.app.Application;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;

import com.keeson.android_cli.commom.BuildType;
import com.keeson.android_cli.commom.Constants;
import com.keeson.android_cli.util.ImageLoadUtils;
import com.keeson.android_cli.util.uifactory.Axis;
import java.util.HashMap;


/**
 * DEBUG
 * SHA1: A9:5B:80:BB:7A:0E:8A:6F:2B:9D:25:97:ED:13:70:5D:FC:0E:17:49
 * SHA256: 16:5B:6C:10:F7:32:39:AC:B9:DE:74:B2:54:ED:FA:A3:86:4B:E9:81:7D:3C:A1:4B:16:22:4D:75:C9:74:2A:4F
 * RELEASE
 * SHA1: 97:39:E4:C9:FB:EB:61:DD:49:E2:76:AD:C6:F6:1B:5C:52:4C:8C:E0
 * SHA256: 00:F5:E5:F9:D7:CD:A6:0E:7D:94:56:23:BE:46:ED:75:30:A8:F4:61:C2:B4:EA:14:88:52:23:50:F5:05:51:21
 */
public class App extends Application {

    private static App mContext;

    private static Handler mHandler;
    private static BuildType mBuildType;


    /**
     * 当前版本环境，打包版本只需要修改此配置
     * RELEASE-生产环境、DEVELOP-开发环境、TEST-测试环境
     *
     * @return
     */
    public static BuildType getBuildType() {
        return BuildType.DEV;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        init();
    }

    public static App getApp() {
        return mContext;
    }

    public static Handler getHandler() {
        return mHandler;
    }

    /**
     * 初始化操作
     */
    private void init() {
        mContext = this;
        if (mHandler == null) {
            mHandler = new Handler(Looper.myLooper());
        }
        mBuildType = getBuildType();
        Axis.init(this,1080,1920);//适配初始化,基准宽高
    }

    @Override
    public void onLowMemory() {
        super.onLowMemory();
        ImageLoadUtils.clearImageMemoryCache(this);
    }

    @Override
    public void onTrimMemory(int level) {
        super.onTrimMemory(level);
        switch (level) {
            case TRIM_MEMORY_COMPLETE://内存不足，并且该进程在后台进程列表最后一个，马上就要被清理
                break;
            case TRIM_MEMORY_MODERATE://内存不足，并且该进程在后台进程列表的中部
                break;
            case TRIM_MEMORY_BACKGROUND://内存不足，并且该进程是后台进程
                break;
            case TRIM_MEMORY_UI_HIDDEN://内存不足，并且该进程的UI已经不可见了
                ImageLoadUtils.clearImageMemoryCache(this);
                break;
            case TRIM_MEMORY_RUNNING_CRITICAL://内存不足(后台进程不足3个)，并且该进程优先级比较高，需要清理内存
                break;
            case TRIM_MEMORY_RUNNING_LOW://内存不足(后台进程不足5个)，并且该进程优先级比较高，需要清理内存
                break;
            case TRIM_MEMORY_RUNNING_MODERATE://内存不足(后台进程超过5个)，并且该进程优先级比较高，需要清理内存
                break;
        }
        ImageLoadUtils.onTrimMemory(this, level);
    }

    public static String getBaseUrl() {
        if (mBuildType == BuildType.RELEASE) {
            return Constants.HTTP_BASEURL_RELEASE;
        }
        if (mBuildType == BuildType.TEST) {
            return Constants.HTTP_BASEURL_TEST;
        }
        if (mBuildType == BuildType.DEV) {
            return Constants.HTTP_BASEURL_DEV;
        }
        return "";

    }

}